﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.Entity;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using FrameWork.Components;

namespace FrameWork.web.Code
{
    public class its_KnowledgeBaseCs
    {
        /// <summary>
        /// 查询知识库信息
        /// </summary>
        /// <param name="_its_KnowledgeBaseEntity"></param>
        /// <returns></returns>

        public DataTable Knowledge_Select(its_KnowledgeBaseEntity _its_KnowledgeBaseEntity, int PageIndex, int PageSize)
        {
            SqlParameter[] sp = new SqlParameter[6]{
				new SqlParameter("@KID",SqlDbType.Int),
				new SqlParameter("@Subject",SqlDbType.NVarChar,200),
				new SqlParameter("@Content",SqlDbType.NVarChar,200),
				new SqlParameter("@KeyWord",SqlDbType.NVarChar,50),
				new SqlParameter("@PageIndex",SqlDbType.Int),
				new SqlParameter("@PageSize",SqlDbType.Int),
			
			};
            //
            if (_its_KnowledgeBaseEntity.KID != 0)
            {
                sp[0].Value = _its_KnowledgeBaseEntity.KID;
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.Subject != "")
            {
                sp[1].Value = _its_KnowledgeBaseEntity.Subject.Replace("'","''");
            }
            else
            {
                sp[1].Value = DBNull.Value;
            }

            sp[1].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.Content != "")
            {
                sp[2].Value = _its_KnowledgeBaseEntity.Content.Replace("'","''");
            }
            else
            {
                sp[2].Value = DBNull.Value;
            }

            sp[2].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.KeyWord != "")
            {
                sp[3].Value = _its_KnowledgeBaseEntity.KeyWord.Replace("'","''");
            }
            else
            {
                sp[3].Value = DBNull.Value;
            }

            sp[3].Direction = ParameterDirection.Input;


           
            sp[4].Value = PageIndex;
            

            sp[4].Direction = ParameterDirection.Input;


          
            sp[5].Value =PageSize;
         
            sp[5].Direction = ParameterDirection.Input;


            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.its_Knowledge_Select", sp);
                DataTable dt = ds.Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 知识库记录数量
        /// </summary>
        /// <param name="_its_KnowledgeBaseEntity"></param>
        /// <returns></returns>
        public int Knowledge_Count(its_KnowledgeBaseEntity _its_KnowledgeBaseEntity)
        {
            SqlParameter[] sp = new SqlParameter[4]{
				new SqlParameter("@KID",SqlDbType.Int),
				new SqlParameter("@Subject",SqlDbType.NVarChar,200),
				new SqlParameter("@Content",SqlDbType.NVarChar,200),
				new SqlParameter("@KeyWord",SqlDbType.NVarChar,50),
			
			};
            //
            if (_its_KnowledgeBaseEntity.KID != 0)
            {
                sp[0].Value = _its_KnowledgeBaseEntity.KID;
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.Subject != "")
            {
                sp[1].Value = _its_KnowledgeBaseEntity.Subject.Replace("'","''");
            }
            else
            {
                sp[1].Value = DBNull.Value;
            }

            sp[1].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.Content != "")
            {
                sp[2].Value = _its_KnowledgeBaseEntity.Content.Replace("'", "''");
            }
            else
            {
                sp[2].Value = DBNull.Value;
            }

            sp[2].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.KeyWord != "")
            {
                sp[3].Value = _its_KnowledgeBaseEntity.KeyWord.Replace("'", "''");
            }
            else
            {
                sp[3].Value = DBNull.Value;
            }

            sp[3].Direction = ParameterDirection.Input;


            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.its_Knowledge_Count", sp);
                DataTable dt = ds.Tables[0];
                return int.Parse(dt.Rows[0][0].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 知识库归纳
        /// </summary>
        /// <param name="_its_KnowledgeBaseEntity"></param>
        public void KnowledgeBase_KBCollect(its_KnowledgeBaseEntity _its_KnowledgeBaseEntity)
        {
            SqlParameter[] sp = new SqlParameter[10]{
				new SqlParameter("@KID",SqlDbType.Int),
				new SqlParameter("@Status",SqlDbType.Int),
				new SqlParameter("@Subject",SqlDbType.NVarChar,400),
				new SqlParameter("@Content",SqlDbType.NText),
				new SqlParameter("@KeyWord",SqlDbType.NVarChar,100),
				new SqlParameter("@Attachment",SqlDbType.VarChar,255),
				new SqlParameter("@DocNo",SqlDbType.VarChar,20),
				new SqlParameter("@UserID",SqlDbType.Int),
				new SqlParameter("@UserName",SqlDbType.NVarChar,40),
				new SqlParameter("@CollateDAT",SqlDbType.DateTime),
			
			};
            //
            if (_its_KnowledgeBaseEntity.KID != int.MinValue)
            {
                sp[0].Value = _its_KnowledgeBaseEntity.KID;
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            //

            sp[1].Value = _its_KnowledgeBaseEntity.Status;
            sp[1].Direction = ParameterDirection.Input;


            //

            sp[2].Value = _its_KnowledgeBaseEntity.Subject;
            sp[2].Direction = ParameterDirection.Input;


            //

            sp[3].Value = _its_KnowledgeBaseEntity.Content;
            sp[3].Direction = ParameterDirection.Input;


            //

            sp[4].Value = _its_KnowledgeBaseEntity.KeyWord;
            sp[4].Direction = ParameterDirection.Input;


            //

            sp[5].Value = _its_KnowledgeBaseEntity.Attachment;
            sp[5].Direction = ParameterDirection.Input;


            //

            sp[6].Value = _its_KnowledgeBaseEntity.DocNo;
            sp[6].Direction = ParameterDirection.Input;



            //
            if (_its_KnowledgeBaseEntity.UserID != int.MinValue)
            {
                sp[7].Value = _its_KnowledgeBaseEntity.UserID;
            }
            else
            {
                sp[7].Value = DBNull.Value;
            }

            sp[7].Direction = ParameterDirection.Input;


            //

            sp[8].Value = _its_KnowledgeBaseEntity.UserName;
            sp[8].Direction = ParameterDirection.Input;


            //
            if (_its_KnowledgeBaseEntity.CollateDAT != DateTime.MinValue)
            {
                sp[9].Value = _its_KnowledgeBaseEntity.CollateDAT;
            }
            else
            {
                sp[9].Value = DBNull.Value;
            }

            sp[9].Direction = ParameterDirection.Input;


            try
            {
                SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.its_KnowledgeBase_KBCollect", sp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
